<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>用户信息维护</title>
    <script src="../../resources/app/all.js" type="text/javascript"></script>
    <style type="text/css">
        a:link {
            text-decoration: none;
        }

        a:visited {
            text-decoration: none;
        }

        a:hover {
            text-decoration: none;
        }

        a:active {
            text-decoration: none;
        }

        #tag_ids2 a {
            padding: 2px 5px;
            background: #5FB878;
            border-radius: 2px;
            color: #fff;
            display: block;
            line-height: 20px;
            height: 24px;
            margin: 2px 5px 2px 0;
            float: left;
        }

    </style>
</head>
<body class="easyui-layout" data-options="fit:true">

<div data-options="region:'center'" style="padding: 5px;">
    <form class="layui-form layui-form-pane" action="" id="form" lay-filter="example">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">用户名</label>
                <div class="layui-input-block">
                    <input type="hidden" id="id" name="id">
                    <input type="hidden" id="deptId" name="deptId">
                    <input type="text" name="realName" lay-verify="required" autocomplete="off" placeholder="请输入用户名"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">归属部门</label>
                <div class="layui-input-block">
                    <input type="text" id="deptName" disabled="true" name="deptName" autocomplete="off"
                           placeholder="请输入目录"
                           class="layui-input layui-disabled">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">身份证号</label>
                <div class="layui-input-block">
                    <input type="text" name="idCard" lay-verify="required|idCard" autocomplete="off"
                           placeholder="请输入身份证号"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">联系电话</label>
                <div class="layui-input-block">
                    <input type="text" name="phone" lay-verify="required|phone|number" autocomplete="off"
                           placeholder="请输入联系电话"
                           class="layui-input">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">年龄</label>
                <div class="layui-input-block">
                    <input type="text" name="age" lay-verify="required|number" autocomplete="off" placeholder="请输入年龄"
                           class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">性别</label>
                <div class="layui-input-block">
                    <input type="radio" name="sex" value="0" title="男" checked="">
                    <input type="radio" name="sex" value="1" title="女">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">登录账号</label>
            <div class="layui-input-block">
                <input type="text" name="account" disabled="true" lay-verify="required|account" autocomplete="off"
                       placeholder="请输入登录账号"
                       class="layui-input layui-disabled">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">登录密码</label>
            <div class="layui-input-block">
                <input type="password" name="password" lay-verify="required|password" autocomplete="off"
                       placeholder="请输入登录密码"
                       class="layui-input">
            </div>
        </div>
    </form>
</div>
<div data-options="region:'south',border:false">
    <div class="dialog-button">
        <button id="save" class="layui-btn layui-btn-normal">确定</button>
        <button id="cancel" class="layui-btn layui-btn-primary">取消</button>
    </div>
</div>

<script>
    layui.use(['form', 'layedit', 'laydate'], function () {
        var form = layui.form
            , layer = layui.layer;
        let parData = ToolUtil.OpenData();
        if (parData.act == 'edit') {
            let data = parData.data;
            form.val('example', JSON.parse(JSON.stringify(data)));
        }
        //自定义验证规则
        form.verify({
            account: function (value) {
                if (value.length < 5) {
                    return '登录账号至少得5个字符啊';
                }
            },
            password: [
                /^[\S]{6,12}$/
                , '密码必须6到12位，且不能出现空格'
            ],
            idCard: [
                /^[1-9][0-9]{5}(19|20)[0-9]{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2][0-9]|31)|(04|06|09|11)(0[1-9]|[1-2][0-9]|30)|02(0[1-9]|[1-2][0-9]))[0-9]{3}([0-9]|x|X)$/
                , '当前身份证号填写不正确'
            ]
        });


        layui.$('#save').on('click', function () {
            let data = ToolUtil.FormJSON("form");
            ToolUtil.PUT({
                url: global.api_url + '/sys/sysUser/updateUser',
                data: JSON.stringify(data),
                async: false,
                success: function (obj) {
                    if (obj && obj.code === '00') {
                        layer.alert(obj.msg);
                    } else if (obj.code === '98' || obj.code === '97') {
                        location.href = global.loginUrl;
                    } else {
                        layer.alert(obj.msg,{icon:5});
                    }
                }
            });
        });
        layui.$('#cancel').on('click', function () {
            clear();
        });

        function clear() {
            let index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);
            layer.close(index);
        }


    });
</script>
</body>
</html>